#!/bin/bash

set -e          # exit on error
set -o pipefail # exit on pipeline error
set -u          # treat unset variable as error

. /minioslib || exit 1

SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"

pkg update

if [ $PACKAGE_VARIANT = "novice" ]; then
    PACKAGE_LIST="$SCRIPT_DIR/$PACKAGE_VARIANT.list"
else
    PACKAGE_LIST="$SCRIPT_DIR/package.list"
fi

# install packages
case $DISTRIBUTION in
bookworm)
    install_packages --package-list "$PACKAGE_LIST" --replace-packages "telegram-desktop=telegram-desktop/$DISTRIBUTION-backports"
    ;;
*)
    install_packages --package-list "$PACKAGE_LIST"
    ;;
esac

if grep -q 'imagemagick' "$PACKAGE_LIST"; then
    rm -f /usr/share/applications/display-im6.q16.desktop
fi
if grep -q 'obs-studio' "$PACKAGE_LIST"; then
    if [ -f /usr/share/icons/hicolor/256x256/apps/com.obsproject.Studio.png ]; then
        mv /usr/share/icons/hicolor/256x256/apps/com.obsproject.Studio.png /usr/share/pixmaps/
    elif [ -f /usr/share/icons/hicolor/256x256/apps/obs.png ]; then
        mv /usr/share/icons/hicolor/256x256/apps/obs.png /usr/share/pixmaps/
    fi
fi

update-icon-caches /usr/share/icons/*
